package com.bwie.app.controller;

import com.bwie.app.service.AppService;
import com.bwie.common.domain.Goods;
import com.bwie.common.domain.Sort;
import com.bwie.common.domain.User;
import com.bwie.common.domain.request.GoodsReq;
import com.bwie.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;


@RestController
@RequestMapping("/app")
public class AppController {
    @Autowired
    private AppService appService;

    /**
     * 列表
     * @param req
     * @return
     */
    @PostMapping("/list")
    public Result<List<Goods>> list(@RequestBody GoodsReq req){
        List<Goods> list = appService.list(req);
        return Result.success(list);
    }
    /**
     * 回显
     */
    @PostMapping("/echo")
    public Result<Goods> echo(@RequestParam Integer id){
        Goods goods = appService.echo(id);
        return Result.success(goods);
    }
    /**
     * 下拉框
     */
    @GetMapping("/dropDownBox")
    public Result<List<Sort>> dropDownBox(){
        List<Sort> list = appService.dropDownBox();
        return Result.success(list);
    }

    /**
     * 购买
     */
    @PostMapping("/buy")
    public Result buy(@RequestParam Integer userId, @RequestParam BigDecimal points){
        appService.buy(userId,points);
        return Result.success("购买成功");
    }
}
